package com.woniuxy.factory.configuration;

import com.woniuxy.factory.Interceptor.LoginInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


@Configuration
public class MyWebmvcConfig  {
    @Bean
    public WebMvcConfigurer mvcDonfigurer() {
        return new WebMvcConfigurer() {
            @Override
            public void addViewControllers(ViewControllerRegistry registry) {
                //用户请求-----ViewName就是模板引擎
                registry.addViewController("/").setViewName("/page/login-1.html");
                /*registry.addViewController("/index.html").setViewName("login.html");
                registry.addViewController("/main").setViewName("/index.html");*/
            }
            //配置拦截器所要拦截的路径
            @Override
            public void addInterceptors(InterceptorRegistry registry) {
                registry.addInterceptor(new LoginInterceptor())
                        //选择拦截的路径
                        .addPathPatterns("/**")
                        //剔除不需要拦截的路径
                        .excludePathPatterns("/page/login-1.html","/verification","/css/**","/lib/**","/login","/images/**","/js/**","/api/**");
            }
        };
    }



}